const {
  DataTypes
} = require('sequelize');

const Goods = require('../model/goods');
const seq = require('../db/seq');
const goods = Goods(seq);

module.exports = sequelize => {
  const attributes = {
    user_id: {
      type: DataTypes.STRING(255),
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "用户id",
      field: "user_id"
    },
    goods_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "商品id",
      field: "goods_id"
    },
    goods_number: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: null,
      primaryKey: false,
      autoIncrement: false,
      comment: "商品数量",
      field: "goods_number"
    },
    id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: null,
      primaryKey: true,
      autoIncrement: true,
      comment: "购物车id",
      field: "id"
    }
  };
  const options = {
    tableName: "cart",
    comment: "",
    indexes: []
  };

  const CartModel = sequelize.define("cart_model", attributes, options);
  CartModel.belongsTo(goods, {
    foreignKey: 'goods_id',
    as: 'goods_info',
  })

  return CartModel;
};